package com.dy.hander;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;

/**
 * @ClassName:
 * @Author: 仄言in
 * @Desctiption: (描述)
 * @Date: 2021/7/27 15:56
 * @Version 1.0 (版本)
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    /**
     * 插入时的填充策略
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill....");
        this.setFieldValByName("createTime", new Timestamp(System.currentTimeMillis()),metaObject);
        this.setFieldValByName("updateTime", new Timestamp(System.currentTimeMillis()),metaObject);
        this.setFieldValByName("rowVersion", 1,metaObject);
        this.setFieldValByName("deleted", 0,metaObject);
    }
    /**
     * 更新时的填充策略
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start insert fill....");
        this.setFieldValByName("updateTime", new Timestamp(System.currentTimeMillis()),metaObject);
    }
}
